<template>
	<div class="wechat-bind">
	<h1>添加文章</h1>

		<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
			<el-form-item label="标题" prop="title">
				<el-input v-model="ruleForm.title"></el-input>
			</el-form-item>
			<el-form-item label="关键词" prop="keyword">
				<el-input type="textarea" v-model="ruleForm.keyword"></el-input>
			</el-form-item>
			<el-form-item label="描述" prop="description">
				<el-input type="textarea" v-model="ruleForm.description"></el-input>
			</el-form-item>
			<el-form-item label="内容" prop="content">
				<vue-editor v-model="ruleForm.content"></vue-editor>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
				<el-button @click="resetForm('ruleForm')">重置</el-button>
			</el-form-item>
		</el-form>
</div>
</template>
<script>
	import { VueEditor } from 'vue2-editor'
 
  export default {
  	name:'ArticleAdd',
  	components: {
      VueEditor
   },
    data() {
      return {
          apiUrl:apiUrl,
        ruleForm: {
            title: '',
            keyword: '',
            description: '',
			content: '',
        },
        rules: {
          title: [
            { required: true, message: '请输入标题', trigger: 'blur' },
          ],
          content: [
            { required: true, message: '请输入内容', trigger: 'blur' }
          ]
        }
      };
    },
    mounted () {
      this.$nextTick(function () {
//          this.load();//概况
      })
  },
	computed:{
  	  submitUrl(){
  	      return this.apiUrl+'Article/add';
	  }
	},
    methods: {
    	//概况数据获取
//      load() {
//          this.$http.get('/')
//          .then(function (response) {
//            console.log(response);
//          })
//          .catch(function (response) {
//            console.log(response);
//          });
//      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
              this.$http.post(this.submitUrl, this.ruleForm).then(response => {
                  if(response.data.status==1){
                      this.$message.success('保存成功');
                      this.$router.push('/article/list/1');
                  }else{
                      this.$message.error('保存失败');
                  }
              }, response => {
                  this.$message.error('保存失败');
                  console.log(response);
              });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
